home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * *
- /*
- /* HEAR ME!
- /*
- /* by Joseph Laffey
- /*
- /* AOL: JoeLaff
- /* CIS: 70712,2306
- /*
- /* * * * * * * * * * * * * * * * * * * * * *
- /*
- /* This program will play a sound resource and put up nifty cursors.
- /*
- /* Use freely to distribute HEAR ME!s with your programs or to friends.
- /*
- /* * * * * * * * * * * * * * * * * * * * * *
- /*
- /* Simply paste in your own 'snd ' resource with the appropriate id.
- /*
- /* * * * * * * * * * * * * * * * * * * * * *
- /*
- /* Make sure you allocate enough application memory for your 'snd ' resource!!
- /*
- /* * * * * * * * * * * * * * * * * * * * * *
- */
-
- #include <Sound.h>
- #include <GestaltEqu.h>
- #include <Types.h>
-
- #define VOLUME 7 /* The volume level (0-7) at which to play the sound */
- #define SND_ID 17000 /* The resource id of the 'snd ' resource */
- #define NIL_POINTER 0L /* Nil pointer for passing to SndPlay routine */
- #define SPEAKER_CURS_ID 401 /* The resource id of the speaker cursor */
- #define EXIT_CURS_ID 501 /* The resource id of the "click to exit" cursor */
- #define RED_CURS_ID 128 /* The resource id of the red square cursor */
- #define YELLOW_CURS_ID 129 /* The resource id of the yellow square cursor */
- #define BLACK_CURS_ID 129 /* The resource id of the black square cursor */
- #define WHITE_CURS_ID 129 /* The resource id of the white square cursor */
- #define BLINK_SPEED 2 /* The delay between cursor flashes */
- #define NUM_BLINK 15 /* The number of times to blink the cursor */
-
- void main( void )
- {
-
- SCStatus soundStatus; /* the sound status */
- SndChannelPtr sndChannel;
- Handle theSnd; /* Holds the sound resource */
- short theVol; /* Holds the current volume level for reset */
- CCrsrHandle theCCursor; /* Holds the color cursor resource */
- CCrsrHandle theCCursor2; /* Holds the color cursor resource */
- CursHandle theCursor; /* Holds the B&W cursor resource */
- CursHandle theCursor2; /* Holds the B&W cursor resource */
- OSErr theErr; /* Holds the errors result */
- long gestaltAnswer; /* Holds the gestalt answer */
- Boolean noQuit = TRUE; /* Stops the sound */
- int i; /* Counter */
-
-
- /**************/
-
- /** Check for Color QD **/
-
- theErr = Gestalt( gestaltQuickdrawVersion, &gestaltAnswer ); /* check for colorQD */
- if( theErr )
- ExitToShell(); /* quit if there is an error */
- if( gestaltAnswer ) /* if the version is higher than 0 then Color QD is present */
- {
- theCCursor = GetCCursor( RED_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- theCCursor2 = GetCCursor( YELLOW_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- for( i = 0; i < NUM_BLINK; i++ )
- {
- SetCCursor(theCCursor); /* set the cursor */
- Delay( BLINK_SPEED, 0 ); /* delay for 2 tick counts (1/60ths of a sec.) */
-
- SetCCursor(theCCursor2); /* set the cursor */
- Delay( BLINK_SPEED, 0 ); /* delay for 2 tick counts (1/60ths of a sec.) */
-
- }
-
-
- theCCursor = GetCCursor( SPEAKER_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- SetCCursor(theCCursor); /* set the cursor */
- }
- else
- {
- theCursor = GetCursor( SPEAKER_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- theCursor2 = GetCursor( BLACK_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- for( i = 0; i < NUM_BLINK; i++ )
- {
- SetCursor(*theCursor); /* set the cursor */
- Delay( BLINK_SPEED, 0 ); /* delay for 2 tick counts (1/60ths of a sec.) */
-
- SetCursor(*theCursor2); /* set the cursor */
- Delay( BLINK_SPEED, 0 ); /* delay for 2 tick counts (1/60ths of a sec.) */
- }
-
-
-
- theCursor = GetCursor( WHITE_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- SetCursor( *theCursor ); /* set the cursor */
- }
-
-
- /** Get and set the volume **/
-
- GetSoundVol( &theVol ); /* get the initial volume setting */
- SetSoundVol( VOLUME ); /* set the volume to the desired level */
-
- /** Do the sound **/
-
-
- sndChannel = (SndChannelPtr) NIL_POINTER; /* Set the channel to Nil */
-
- theErr = SndNewChannel( &sndChannel, 0, /* Allocate a new sound channel */
- (long int) 0, (SndCallBackProcPtr) 0 );
- if( theErr )
- ExitToShell(); /* quit if there is an error */
-
-
- theSnd = Get1Resource( 'snd ', SND_ID ); /* load in the sound resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- Delay(20, 0 ); /* delay for 20 tick counts (1/60ths of a sec.) */
-
-
- theErr = SndPlay( sndChannel, theSnd , TRUE ); /* play the sound asychronously */
- if( theErr )
- ExitToShell(); /* quit if there is an error */
-
-
- theErr = SndChannelStatus( sndChannel, /* get the sound channel status */
- sizeof( soundStatus ), &soundStatus );
- if( theErr )
- ExitToShell(); /* quit if there is an error */
-
-
-
-
- while( noQuit && (soundStatus.scChannelBusy ) )
- noQuit = !Button(); /* Keep playing the sound unless
- there is a mouse click */
-
-
- /** ready to Quit **/
-
- if( gestaltAnswer ) /* if the version is higher than 0 then Color QD is present */
- {
- theCCursor = GetCCursor( EXIT_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- SetCCursor(theCCursor); /* set the cursor */
- }
- else
- {
- theCursor = GetCursor( EXIT_CURS_ID ); /* load in the cursor resource */
- if( ResError() )
- ExitToShell(); /* quit if there is an error */
-
- SetCursor( *theCursor ); /* set the cursor */
- }
-
- Delay( 50, 0 ); /* delay for 50 tick counts (1/60ths of a sec.) */
- while( !Button() ); /* wait for a click */
-
- theErr = SndDisposeChannel( sndChannel, TRUE ); /* Make sure the channel is silent */
-
-
- SetSoundVol( theVol ); /* reset the sound level */
- ReleaseResource( theSnd ); /* release the sound resource */
- ReleaseResource( theCCursor ); /* release the color cursor resource */
- ReleaseResource( theCursor ); /* release the cursor resource */
-
-
-
- }